package com.jingbo.servlet;

import com.jingbo.DAO.User.Adduserimpl;
import com.jingbo.Dbutil.StrUtils;
import com.jingbo.entity.User;
import com.jingbo.service.register.registeruserimpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.jingbo.servlet
 * @Description:
 * @Date 2022/5/27 12:41
 */
@WebServlet("/user")
public class registerUser extends BeanServlet {

    public  String login(HttpServletRequest request, HttpServletResponse response){
        String username = request.getParameter("username");
        String pwd =request.getParameter("pwd1");
        String pwd1 =request.getParameter("pwd2");
        if(!StrUtils.empty(username)|| !StrUtils.empty(pwd)||! StrUtils.empty(pwd1)){
            request.setAttribute("msg","用户名，密码不能为空");
            return "redirect:/register.jsp";
        }
        if(pwd1!=pwd1){
            request.setAttribute("msg","俩次密码不能正确");
            //俩次密码不正确的话 跳转到 注册页面
            return "redirect:/register.jsp";
        }
        registeruserimpl user1 = new registeruserimpl(new Adduserimpl());
        Boolean aBoolean = user1.AddUser(new User(username, pwd, "1"));
        if(aBoolean){
            return "redirect:/record.jsp";
        }else{
            return "redirect:/register.jsp";
        }
    }
}
